/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tp_imag.model;

import java.io.Serializable;
import java.util.Iterator;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Persistence;

/**
 *
 * @author Administrador
 */
@Entity
public class SSSelement implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String valoresBase;
    private double[] valores;
    private String pathOriginal;

    private final String SEPARADOR = ";";

    public String getPathOriginal() {
        return this.pathOriginal;
    }

    public void setPathOriginal(String pathOriginal) {
        this.pathOriginal = pathOriginal;
    }

    public String getValoresBase() {
        return valoresBase;
    }

    public void setValoresBase(String valoresBase) {
        this.valoresBase = valoresBase;
    }

    public double[] getValores() {
        if (valores == null || valores.length == 0){
            valores = new double[valoresBase.length()];
            String[] val = valoresBase.split(SEPARADOR);
            for (int i = 0; i < val.length; i++) {
                valores[i] = Double.valueOf(val[i]);
            }
        }
        return valores;
    }

    public void setValores(double[] valores) {
        this.valores = valores;
        valoresBase ="";
        for (int i = 0; i < valores.length; i++) {
            valoresBase += String.valueOf(valores[i])+SEPARADOR;
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }


    @Override
    public String toString() {
        return "tp_imag.model.SSSelement[id=" + id + "]";
    }

    public void persist(Object object) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersistenceUnit");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            em.persist(object);
            em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }



}
